import { observer } from './observer.js'

(function(doc) {
  var uname = doc.querySelector('#uname')
  var uage = doc.querySelector('#uage')
  var utel = doc.querySelector('#utel')
  var sub = doc.querySelector('#sub')
  var info = doc.querySelector('#info')
  var userinfo = observer({
    uname: '',
    uage: '',
    utel: ''
  }, info)

  console.log(userinfo)

  var init = function() {
    bindEvent()
  }

  var bindEvent = function() {
    sub.addEventListener('click', handelSubClick, false)
  }

  function handelSubClick() {
    var _uname = uname.value.trim()
    var _uage = uage.value.trim()
    var _utel = utel.value.trim()

    if (_uname && (_uname !== userinfo.uname)) {
      userinfo.uname = _uname
    }
    if (_utel && (_utel !== userinfo.utel)) {
      userinfo.utel = _utel
    }
    if (_uage && (_uage !== userinfo.uage)) {
      userinfo.uage = _uage
    }
    uname.value = ''
  }

  init()
})(document)

